// src/BudgetManager.java

public class BudgetManager {
    private double monthlyBudget;

    // 设置每月预算
    public void setMonthlyBudget(double budget) {
        if (budget <= 0) {
            throw new IllegalArgumentException("预算必须为正数");
        }
        this.monthlyBudget = budget;
    }

    // 获取当前的每月预算
    public double getMonthlyBudget() {
        return monthlyBudget;
    }

    // 计算剩余预算
    public double calculateRemainingBudget(double totalExpenditure) {
        return monthlyBudget - totalExpenditure;
    }

    // 计算支出与预算的比例（百分比）
    public double calculateExpenditureRatio(double totalExpenditure) {
        if (monthlyBudget == 0) {
            throw new IllegalStateException("未设置预算");
        }
        return (totalExpenditure / monthlyBudget) * 100;
    }
}
